
//    实现交换两个变量的值。要求：需要交换实参的值。
class MyValue{
    public int val;
}
public class text2 {
    public static void swap(MyValue myv1, MyValue myv2){ //这里的类型不能是int  只能是MyValue
        int tmp = myv1.val;
        myv1.val = myv2.val;
        myv2.val = tmp;
    }
    public static void main(String[] args) {
        MyValue myValue1 = new MyValue();
        myValue1.val = 10;
        MyValue myValue2 = new MyValue();
        myValue2.val = 20;
        System.out.println("val1: " + myValue1.val + "  val2: " + myValue2.val);
        swap(myValue1,myValue2);
        System.out.println("=======交换之后============");
        System.out.println("val1: " + myValue1.val + "  val2: " + myValue2.val);

    }
}
